package controller;

import util.Parameters;

import engine.EngineFactory;
import engine.EngineType;
import engine.HTMLBuilder;
import entity.Project;
import entity.dao.DAOFactory;
import entity.dao.ProjectDAO;

public class Controller {
	
	public Controller(){
	}
	
	
	public boolean save(String guiDescriptor, String dataProvider, String projectName){
		
		DAOFactory daof = DAOFactory.getFactory(Parameters.DAO_TYPE);
		ProjectDAO pm = daof.getPersistanceManager();
		
		if(!pm.saveData(guiDescriptor, dataProvider, projectName))
			return false;
			
		return true;
	}
	
	public boolean saveAs(Project project){
		
		DAOFactory daof = DAOFactory.getFactory(Parameters.DAO_TYPE);
		ProjectDAO pm = daof.getPersistanceManager();
		
		if(!pm.saveDataAs(project))
			return false;
			
		return true;
	}
	
	public Project load(int idproject){
		
		DAOFactory daof = DAOFactory.getFactory(Parameters.DAO_TYPE);
		ProjectDAO pm = daof.getPersistanceManager();
		
		return pm.load(idproject);
	}
	
	public Project[] loadAllProjects(){
		
		Project[] projects = null;
		
		DAOFactory daof = DAOFactory.getFactory(Parameters.DAO_TYPE);
		ProjectDAO pm = daof.getPersistanceManager();
		
		projects = pm.loadAllProject();
		
		return projects;
	}
	
	public boolean generateCode(Project project){
		
		EngineFactory ef = EngineFactory.getEngine(Parameters.ENGINE_TYPE);
		HTMLBuilder htmlb = ef.getHTMLBuilder();
		
		htmlb.generateCode(project);
		
		return true;
	}
}
